<template>
<div>
  <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" :label-position="labelPosition" label-width="80px">
    <el-row>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <el-form-item label="代码" size="mini">
            <el-input class="myinput" v-model="dataForm.code" placeholder="代码" clearable width="50%"></el-input>
          </el-form-item>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple-light">
          <el-form-item label="名字" size="mini">
            <el-input class="myinput" v-model="dataForm.codeName" placeholder="名字" clearable></el-input>
          </el-form-item>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <div class="grid-content bg-purple">
          <el-form-item label="工作部门" size="mini">
            <el-select class="myinput" v-model="dataForm.workcellId" clearable placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple-light">
          <el-form-item label="用途" size="mini">
            <el-input class="myinput" v-model="dataForm.usePurpose" placeholder="用途" clearable></el-input>
          </el-form-item>
        </div>
      </el-col>
    </el-row>
    <el-row>

      <el-col :span="12" :offset="12">
        <div class="grid-content bg-purple-light">
          <el-form-item size="mini">
            <el-button type="primary" icon="el-icon-search" @click="getDataList()">查询</el-button>
            <!--        <el-button  type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
            <el-button plain icon="el-icon-delete" @click="clearDataForm()">清空</el-button>
            <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
            <el-button type="info" :disabled="dataList.length <=0">导出本页<i class="el-icon-upload el-icon--right"></i></el-button>
            <el-button type="info" :disabled="dataList.length <=0">导出全部<i class="el-icon-upload el-icon--right"></i></el-button>
          </el-form-item>
        </div>
      </el-col>
    </el-row>
  </el-form>
  <hr style="opacity: 0.3"><br>
  <el-table
    :data="dataList"
    border
    v-loading="dataListLoading"
    @selection-change="selectionChangeHandle"
    style="width: 100%;"
    size="mini">
    <el-table-column
      type="selection"
      header-align="center"
      align="center"
      width="50">
    </el-table-column>
    <el-table-column
      prop="code"
      header-align="center"
      align="center"
      label="工夹具代码">
    </el-table-column>
    <el-table-column
      prop="seqId"
      header-align="center"
      align="center"
      label="序列号">
    </el-table-column>
    <el-table-column
      prop="codeName"
      header-align="center"
      align="center"
      label="名字">
    </el-table-column>
    <el-table-column
      prop="outcomeTime"
      header-align="center"
      align="center"
      label="出库时间">
    </el-table-column>
    <el-table-column
      prop="userName"
      header-align="center"
      align="center"
      label="出库人">
    </el-table-column>
    <el-table-column
      fixed="right"
      header-align="center"
      align="center"
      width="150"
      label="操作">
      <template slot-scope="scope">
        <el-button type="primary" size="small" @click="updateHandle(scope.row.id)">入库</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    @size-change="sizeChangeHandle"
    @current-change="currentChangeHandle"
    :current-page="dataForm.pageIndex"
    :page-sizes="[10, 20, 50, 100]"
    :page-size="dataForm.pageSize"
    :total="totalPage"
    layout="total, sizes, prev, pager, next, jumper">
  </el-pagination>
  <update v-if="updateVisible" ref="update" @refreshDataList="getDataList"></update>
</div>
</template>

<script>
import Update from "../people/peoplemanagement-update";

export default {
  name: "outgoingjig",
  data(){
    return {
      labelPosition:'left',
      options: [
        {
          label:'JW01',
          value: 1
        },
        {
          label:'JW02',
          value: 2
        },
        {
          label:'JW03',
          value: 3
        },
        {
          label:'JW04',
          value: 4
        },
        {
          label:'JW05',
          value: 5
        }
      ],
      dataForm: {
        pageIndex: 1,
        pageSize: 10
      },
      dataList: [],
      // pageIndex: 1,
      // pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      updateVisible: false
    }
  },
  components:{
    Update
  },
  activated () {
    this.getDataList()
  },
  methods: {
    getDataListByLike() {
      this.$http.post(`http://localhost:10000/gongjiajumain/scrapsubmithistory/getformdata`, this.dataForm)
        .then(res => {
          console.log(this.dataForm)
          console.log("传输成功")
        })
    },
    //清空表格
    clearDataForm() {
      this.dataForm = {}
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.$http.post(`http://localhost:10000/gongjiajumain/outgoingjig/list1`,this.dataForm)
        .then(data=>{
          if (data.data && data.data.code === 0) {
            this.dataList = data.data.page.list
            this.totalPage = data.data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.dataForm.pageSize = val
      this.dataForm.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.dataForm.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    updateHandle(id) {
      this.updateVisible = true
      console.log(this.updateVisible)
      console.log(id)
      this.$nextTick(() => {
        this.$refs.update.init(id)
      })
    },
    // 删除
    deleteHandle(id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: "http://localhost:10000/gongjiajumain/scrapsubmithistory/delete",
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.el-input__inner{
  width: 490px;
}

</style>
